<template>
  <div class='tabs-container'>
    <div class='tabs'>
      <!--      <div-->
      <!--        v-for="(tab, index) in tabs"-->
      <!--        :key="index"-->
      <!--        :class="{ active: activeTab === index }"-->
      <!--        @click="changeTab(index)"-->
      <!--        class="tabtitle"-->
      <!--      >-->
      <div
        v-for='(tab, index) in tabs'
        :key='index'
        :class='{ active: activeTab === index }'
        class='tabtitle'
      >
        <div class='icon'>
          <a-icon type='tag' theme='filled' :class='{ active: activeTab === index }' />
        </div>
        {{ tab.title }}
        <div class='tiao'></div>
      </div>
    </div>
    <div class='tab-content'>
      <basicInformation ref='basic' v-if='activeTab == 0' @next='nextTab($event)' @projectId='getProjectId($event)' />
      <memberInformation ref='member' v-if='activeTab == 1' :id='projectId' @next='nextTab($event)'
                         @previous='previousTab($event)' />
      <budgetInformation ref='buget' v-if='activeTab == 2' :id='projectId' @next='nextTab($event)'
                         @previous='previousTab($event)' />
      <projectDemonstration ref='project' :id='projectId' v-if='activeTab == 3' @next='nextTab($event)'
                            @previous='previousTab($event)' />
    </div>
  </div>
</template>

<script>
import basicInformation from './basicInformation'
import memberInformation from './memberInformation'
import budgetInformation from './budgetInformation'
import projectDemonstration from './projectDemonstration'

export default {
  components: {
    basicInformation,
    memberInformation,
    budgetInformation,
    projectDemonstration
  },
  mounted() {
    let data = localStorage.getItem('currentPageNum')
    if (data) {
      this.activeTab = Number(data)
    }
  },
  beforeDestroy() {
    localStorage.setItem('currentPageNum', this.activeTab)
  },
  data() {
    return {
      activeTab: 0,
      projectId: null,
      tabs: [
        { title: '基本信息', content: 'Content 1' },
        { title: '成员信息', content: 'Content 2' },
        { title: '预算信息', content: 'Content 3' },
        { title: '项目论证', content: 'Content 4' }
      ]
    }
  },
  methods: {
    getCurrentTab() {
      return this.activeTab
    },
    getData() {
      this.$refs.basic.submitTrigger()
    },
    getData2() {
      this.$refs.member.nextTab(true)
    },
    getData3() {
      this.$refs.buget.nextTab(true)
    },
    getData4() {
      this.$refs.project.save(true)
    },
    getTabNext() {
      return 1
    },
    getMemberNext() {
      return 2
    },
    getBugetNext() {
      return 3
    },
    getProjectNext() {
      return 4
    },
    changeTab(index) {
      this.activeTab = index
    },
    nextTab(value) {
      this.activeTab = value
    },
    getProjectId(projectId) {
      this.projectId = projectId
      console.log('value', projectId)
    },
    previousTab(value) {
      this.activeTab = value
    }
  }
}
</script>

<style lang='less' scoped>
.tabs-container {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: flex-start;
  min-height: 660px;
  width: 100%;

  padding: 10px 20px;
  background: #fff;
}

.tabs {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  .tabtitle {
    margin-bottom: 40px;
    font-size: 16px;
    width: 120px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    cursor: default;
    color: #000;
    font-weight: 800;
    position: relative;

    &:nth-child(4) {
      .tiao {
        border-left: 0 dashed #cacaca !important;
      }
    }

    .icon {
      height: 28px;
      width: 28px;
      border-radius: 50%;
      background: #cacaca;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-right: 8px;
    }

    i {
      font-size: 16px;
      color: #a0a0a0;
    }

    .tiao {
      position: absolute;
      top: 30px;
      left: 14px;
      transform: translate(-50%);
      height: 40px;
      width: 3px;
      border-left: 1px dashed #cacaca;
    }
  }
}

.active {
  color: #0a91ff !important;
}

.tab-content {
  flex: 1;
  min-height: 500px;
  display: flex;

  justify-content: center;
  border-left: 1px solid #e7e7e7;
  padding-left: 10px;

  .basicinformation {
    min-height: 500px;
    width: 100%;
  }
}
</style>
